import request from '@/config/axios'

export interface SpVO {
  id?: number
  name: string
  description?: string
  imageAddress?: string
  status?: number
  createTime?: string
  updateTime?: string
  spNumber?: number
  cgqNumber?: number
}

// SP表 API
export const SpApi = {
  // 查询SP表分页
  getSpPage: async (params: any) => {
    return await request.get({ url: '/system/sp/page', params })
  },

  // 查询SP表详情
  getSp: async (id: number) => {
    return await request.get({ url: '/system/sp/get?id=' + id })
  },

  // 新增SP表
  createSp: async (data: SpVO) => {
    return await request.post({ url: '/system/sp/create', data })
  },

  // 修改SP表
  updateSp: async (data: SpVO) => {
    return await request.put({ url: '/system/sp/update', data })
  },

  // 删除SP表
  deleteSp: async (id: number) => {
    return await request.delete({ url: '/system/sp/delete?id=' + id })
  },

  // 导出SP表 Excel
  exportSp: async (params) => {
    return await request.download({ url: '/system/sp/export-excel', params })
  },

  // 根据视频编号获取视频地址
  getSpBySpNumber: async (spNumber: number) => {
    return await request.get({ url: '/system/sp/get-by-sp-number?spNumber=' + spNumber })
  },

  // 根据传感器编号获取视频地址列表
  getSpListByCgqNumber: async (cgqNumber: number) => {
    return await request.get({ url: '/system/sp/list-by-cgq-number?cgqNumber=' + cgqNumber })
  },

  // 获取所有视频地址列表
  getSpAllList: async () => {
    return await request.get({ url: '/system/sp/list-all' })
  },

  // 上传视频图片
  uploadSpImage: async (file: File) => {
    const formData = new FormData()
    formData.append('file', file)
    return await request.post({ url: '/system/sp/upload-image', data: formData })
  }
}
